package com.sgb.kjwl.viewmodel.manage;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.repository.ManageRepertory;
import com.sgb.kjwl.view.ui.activity.manage.TheEnterpriseOfActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TheEnterpriseOfModel extends BaseViewModel {

    private TheEnterpriseOfActivity activity;
    private ManageRepertory repertory;

    private int page = 1;
    private int size = 20;
    public int total;


    public TheEnterpriseOfModel(TheEnterpriseOfActivity activity, ManageRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    //获取分类列表
    public void getTypeList(boolean isList) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getTypeList().enqueue(new Callback<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> call, Response<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<PickSelectEntity<List<PickSelectEntity>>> list = new ArrayList<>();
                    list.add(new PickSelectEntity("","全部"));
                    list.addAll(response.body().getData());
                    activity.initFragment(list,isList);
                } else {
                    MToast.showLongToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity<List<PickSelectEntity>>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //获取注册资金
    /*public void findCapitalList(List<PickSelectEntity<List<PickSelectEntity>>> typeList) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().findCapitalList().enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK) && response.body().getData() != null) {
                    List<PickSelectEntity> list = response.body().getData();
                    list.get(0).setProjectscale("不限");
                    activity.initFragment(typeList,response.body().getData());
                } else {
                    MToast.showLongToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }*/

}
